package com.cinema.servlet;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cinema.Bean.Hall;
import com.cinema.Bean.Movie;
import com.cinema.Bean.MovieSession;
import com.cinema.dao.IHallDao;
import com.cinema.dao.IMovieDao;
import com.cinema.dao.IMovieSessionDao;
import com.cinema.dao.imp.HallDaoMysql;
import com.cinema.dao.imp.MovieDaoMysql;
import com.cinema.dao.imp.MovieSessionDaoMysql;

public class detailServlet extends HttpServlet {
	
	IMovieDao iMovieDao = new MovieDaoMysql();
	
	IMovieSessionDao iMovieSessionDao = new MovieSessionDaoMysql();

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String method = request.getParameter("method");
		String movieId = request.getParameter("movieId");
		// 正在热映  热门推荐
		List<Movie> hotMovieList=iMovieDao.selectByWhere("movieStat = 1 and movieId != '"+movieId+"'");
		request.setAttribute("hotMovies", hotMovieList);
		
		if ("getMovieDetail".equals(method)) {
			
			if (movieId != null && movieId != "") {
				// 电影信息
				Movie movie = iMovieDao.SelectById(movieId);
				request.setAttribute("movie", movie);
				
				// 场次、场厅信息
				IMovieSessionDao iMovieSessionDao = new MovieSessionDaoMysql();
				List<Map<String, Object>> movieSessionList = iMovieSessionDao.selectByWhere("movieId = '"+ movieId +"'");
				request.setAttribute("movieSessionList", movieSessionList);
				
			} 
		} 
		
		// 将信息传到详情界面
		RequestDispatcher rd=request.getRequestDispatcher("/view/film_detail.jsp");
		rd.forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
